import {messages} from "share/common";
import React, { Component } from "react"
import { Input, Modal } from 'antd'
import { openModal, removeContainer } from "components/method/openModal";
import configureStore from "stores";

const { TextArea } = Input;

class BacklashModal extends Component {

  state = {
    notReceivedReason: '',
    confirmLoading: false
  };

  render() {
    const { visible, onCancel, onOk, afterClose } = this.props;
    const { notReceivedReason, confirmLoading } = this.state;
    let language = configureStore.store.getState().main.language.code;
    return (
      <Modal
        title={messages('expense-14.key467')/*发起反冲*/}
        visible={visible}
        onCancel={onCancel}
        onOk={() => this.setState({ confirmLoading: true }, () => onOk(notReceivedReason, this))}
        afterClose={afterClose}
        confirmLoading={confirmLoading}
      >
        <TextArea
          rows={3}
          placeholder={messages('expense-14.key468',{arg1: language==='zh_cn'?200:500})/*反冲原因，最多输入{arg1}个字符*/}
          maxLength={language === 'zh_cn' ? 200 : 500}
          style={{ resize: 'none' }}
          onChange={e => this.setState({ notReceivedReason: e.target.value })}
        />
      </Modal>
    )
  }

}

BacklashModal.open = function(env) {
  let container;
  return new Promise(resolve => {
    const targetProps = {
      visible: true,
      onOk: (data, context) => close(data, context),
      onCancel: () => close(null),
      afterClose: () => {
        removeContainer(container);
        container = null;
      }
    };
    function close(data, context) {
      let closeModal = () => openModal(BacklashModal, {
        ...targetProps,
        visible: false
      }, env, container);
      if(data !== null) resolve({data, closeModal, context});
      else closeModal();
    }
    container = openModal(BacklashModal, targetProps, env);
  });
};

export default BacklashModal
